﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using TypeMock.ArrangeActAssert;
using Core.Infrastructure.ErrorReportService;

namespace Core.Infrastructure.Test
{
    public class DelegateErrorReportServiceTests
    {
        [Test]
        public void ReportMessage_DelegatePassed_DelegateInvoked()
        {
            bool isCalled = false;
            DelegateErrorReportService errorReported = new DelegateErrorReportService(message => { isCalled = true; }, null, null);

            errorReported.Report("message");

            Assert.IsTrue(isCalled);
        }

        [Test]
        public void ReportException_DelegatePassed_DelegateInvoked()
        {
            bool isCalled = false;
            DelegateErrorReportService errorReported = new DelegateErrorReportService(null, exception => { isCalled = true; }, null);

            errorReported.Report(new Exception());

            Assert.IsTrue(isCalled);
        }

        [Test]
        public void ReportMessageException_DelegatePassed_DelegateInvoked()
        {
            bool isCalled = false;
            DelegateErrorReportService errorReported = new DelegateErrorReportService(null, null, (message, exception) => { isCalled = true; });

            errorReported.Report("message", new Exception());

            Assert.IsTrue(isCalled);
        }

        [Test]
        [ExpectedException(typeof(NotSupportedException))]
        public void ReportMessage_NodelegatesPassed_ThrowNotSupportedException()
        {
            DelegateErrorReportService errorReported = new DelegateErrorReportService(null, null, null);

            errorReported.Report("message");
        }

        [Test]
        [ExpectedException(typeof(NotSupportedException))]
        public void ReportException_NodelegatesPassed_ThrowNotSupportedException()
        {
            DelegateErrorReportService errorReported = new DelegateErrorReportService(null, null, null);

            errorReported.Report(new Exception());
        }

        [Test]
        [ExpectedException(typeof(NotSupportedException))]
        public void ReportMessageException_NodelegatesPassed_ThrowNotSupportedException()
        {
            DelegateErrorReportService errorReported = new DelegateErrorReportService(null, null, null);

            errorReported.Report("message", new Exception());
        }
    }
}
